import { defineStore } from "pinia";
import { ref, computed } from "vue";

export const useUserStore =defineStore('user',()=>{
    const token = ref<string>('');
    const adminid = ref<string>('');
    // 执行这个函数，本地数据库中的token变化，store中token也发生了变化
    const changeToken = (newToken: string) => {
        token.value = newToken;
    };
    const changeAdminId = (newAdminId: string) => {
        adminid.value = newAdminId;
    }

     // 退出的方法
    const loginout = () => {
        token.value = '';
        adminid.value = ''
    }

    // 判断是否登录的函数
    const isLogin = computed<boolean>(() => token.value ? true : false);

    return {
        token,
        adminid,
        changeAdminId,
        changeToken,
        loginout,
        isLogin
    }

}, {
    persist: true,
})